import csv,json

data_map = {}
with open("all_subject_size_trand.csv","rt")as f:
    reader = csv.reader(f)
    for row in reader:
        name = row[0].replace(".txt","")
        ni = int(row[1])
        nj = int(row[2])
        nk = int(row[3])
        count = int(row[4])
        D = (ni-nj)/(ni+nj+nk)
        # print(name,D,count)
        data_map.setdefault(name,[])
        data_map[name].append([D,count])
for k,v in data_map.items():
    v.sort(key=lambda x:x[1])

# print(data_map)

ret_map = {}
for k,v in data_map.items():
    ret_map[k] = [round(item[0], 5)  for item in v]

with open("/tmp/t.json",'wt')as f:
    json.dump(ret_map,f)